package cn.itcast.bos.service.system.Imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.system.PermissionDao;
import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.domain.system.User;
import cn.itcast.bos.service.system.PermissionService;

@Service
@Transactional
public class PermissionServiceImp implements PermissionService {

		@Autowired
		private PermissionDao permissionServiceDao;
	
	@Override
	public List<Permission> findByUser(User  user) {
		  if(user.getUsername().equals("admin")){
			  return permissionServiceDao.findAll();
		  }else{
			  return permissionServiceDao.findByUser(user.getId());
		  }
		
	}

	@Override
	public List<Permission> findAll() {
		return permissionServiceDao.findAll();
	}

	@Override
	public void save(Permission permission) {
		permissionServiceDao.save(permission);	
	}

}
